<?php 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                 DMI Alta ADMINISTRATION																//
//																										//
//   21/04/08 (Filament) : cr�ation de la page																			//
//																										//
//	Cette page est l'accueil de l'administration de DMI Alta												                               			//
//																										//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*
* @package scp
* @version $Id: acp_permissions.php,v 1.59 2007/07/19 20:36:49 acydburn Exp $
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @package acp
*/
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
class dmi_banners
{
	var $u_action;
	var $permission_dropdown;
	
	function main($id, $mode)
	{
		global $db, $user, $auth, $template, $cache;
		global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
		
		//Valeur par d�faut pour le template et les langues :
		$user->add_lang('dmi/general');
		add_permission_language();	
		$template->assign_vars(array(
			"USER_SID" => $user->data['session_id'],
		));

		//Si on a des actions � faire c'est maintenant
		if(isset($_GET['action']) && $_GET['action'] !=  "")
		{
			switch($_GET['action'])
			{
				case "ajout" :
					//On ajoute la banni�re
					
					//On traite le Nom du fichier de la banniere				
					$message_parser = new parse_message();
					$message_parser->banniere = &$_POST['banniere'];
					$message_parser->parse('1' , '1', '1', '1', '1', '1', '1', $config['allow_post_links']);
					
					//On traite la L�gende � afficher sous la box banni�re
					$message_parser->legende = &$_POST['legende'];
					$message_parser->parse('1' , '1', '1', '1', '1', '1', '1', $config['allow_post_links']);
					
					//On traite le Nom du fichier Thumb � afficher sur la page
					$message_parser->thumb = &$_POST['thumb'];
					$message_parser->parse('1' , '1', '1', '1', '1', '1', '1', $config['allow_post_links']);
				
        	//On traite Date initiale de la mise en ligne 
					$message_parser->date = &$_POST['date'];
					$message_parser->parse('1','1', '1', '1', '1', '1', '1', $config['allow_post_links']);	

					//On traite la Cat�gorie de l'image
					$message_parser->cat = &$_POST['cat'];
					$message_parser->parse('1','1', '1', '1', '1', '1', '1', $config['allow_post_links']);
					
          //On traite l'image de fond
					$message_parser->back_color = &$_POST['back_color'];
					$message_parser->parse('1', '1', '1', '1', '1', '1', '1', $config['allow_post_links']);
					
    		  //On ins�re dans la bdd					
					if($_POST['type'] == '' || !isset($_POST['type']))
						$_POST['type'] = 1;
					$ajout_banners = "INSERT INTO dmi_banniere_banniere ( banniere, legende, thumb, date, resume, cat, back_color)  VALUES 
					('".addslashes($message_parser->banniere)."', '".addslashes($message_parser->legende)."', '".addslashes($message_parser->thumb)."',
           '".addslashes($message_parser->date)."','".$_POST['resume']."','".addslashes($message_parser->cat)."','".addslashes($message_parser->back_color)."')";
           
					if(!$requete = mysql_query($ajout_banners))
					{
						//dmi_error("phpBB3/includes/dmi/dmi_links.php","Impossible d'ajouter une banniere : ".mysql_error(),$ajout_banners);
						$template->assign_vars(array(
							"MESSAGE_ECHEC" => true,
							"MESSAGE_TEXTE" => "La banni&egrave;re n'a pas &eacute;t&eacute; ajout&eacute;e, l'erreur a &eacute;t&eacute; signal&eacute;e.<hr>$ajout_banners<br /><br />".mysql_error(),
							"MESSAGE_COULEUR" => "#CC0000",
						));
					}
					else
					{
						$template->assign_vars(array(
							"MESSAGE_REUSSITE" => true,
							"MESSAGE_TEXTE" => "La banni&egrave;re a &eacute;t&eacute; ajout&eacute;e avec succ&egrave;s.",
							"MESSAGE_COULEUR" => "#9AE3AD",
						));
					}
				break;
			}		
		}

		//On prend le mode courant
		$mode = isset($_GET['mode']) ? $_GET['mode'] : "";
		
		switch($mode)
		{
			case "ajout" :
				$this->tpl_name = 'banners/dmi_ajout';	
				
	
				
				
				break;
			case "voir" : 
			default :
				$this->tpl_name = 'banners/dmi_banners';	
				//On liste les banni�res
				$banners = "SELECT * FROM dmi_banniere_banniere ORDER BY date DESC LIMIT 0, 5 ";
				$requete = mysql_query($banners);
				while($banners = mysql_fetch_assoc($requete))
					$template->assign_block_vars('banners', array(
						"TITRE" => stripslashes($banners['resume']),
						"IMAGE" => stripslashes($banners['thumb']),
					));
				break;
		}
		
	}
}

?>
